package com.example.operation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.operation.dto.AdminDto;
import com.example.operation.dto.DispatchDto;
import com.example.operation.service.DispatchService;
import com.example.operation.utils.Result;
import com.example.operation.vo.DispatchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: DispatchController
 * @Description:
 * @Author
 * @Date 2021/11/24
 * @Version 1.0
 */

@Api(tags = "配送费模板")
@RestController
@RequestMapping( "/dispatch")
public class DispatchController {

    @Autowired
    private DispatchService dispatchService;

    @ApiOperation(value = "创建配送费模板接口")
    @PostMapping("/save")
    public Result<String> save(@RequestBody DispatchDto dispatchDto) {
        dispatchService.insert(dispatchDto);
        return Result.ok("配送费模板新增成功");
    }

    @ApiOperation(value = "修改配送费模板接口")
    @PutMapping("/update")
    public Result<String> update(@RequestBody DispatchDto dispatchDto){
        dispatchService.update(dispatchDto);
        return Result.ok("配送费模板修改成功");
    }

    @ApiOperation(value = "配送费模板删除操作接口")
    @DeleteMapping("/delect")
    public Integer delectById(@RequestParam("id") Integer id){
        return dispatchService.delectById(id);
    }

    @ApiOperation(value = "配送费模板分页模糊查询接口")
    @GetMapping("/page")
    public Result<Page<DispatchVo>> pageResult (
            @RequestParam(value = "pageCurret") @ApiParam(value = "当前页码",required = true) Integer pageCurrent,
            @RequestParam(value = "pageSize") @ApiParam(value = "分页条数",required = true) Integer pageSize,
            @RequestParam(value = "pageNumber") @ApiParam(value = "分页页码",required = true) Integer pageNumber,
            @RequestParam(value = "name",required = false) @ApiParam(value = "配送费模板名称") String name){
        Page<DispatchVo> dispatchVoPage = dispatchService.page(pageCurrent,pageSize,pageNumber,name);
        return Result.ok(dispatchVoPage);
    }
}
